package dk.mirasola.systemtraining.bridgewidgets.shared.model.distributionfiltertree;

import dk.mirasola.systemtraining.bridgewidgets.shared.model.Distribution;
import dk.mirasola.systemtraining.bridgewidgets.shared.model.DistributionFilter;

public abstract class DistributionFilterGroupItem extends GroupItem implements DistributionFilter {
    private Boolean inverted = Boolean.FALSE;

    public Boolean getInverted() {
        return inverted;
    }

    public void setInverted(Boolean inverted) {
        this.inverted = inverted;
    }

    public final boolean matches(Distribution distribution) {
        if (distribution == null) {
            throw new IllegalArgumentException("distribution can't be null");
        }
        if (inverted) {
            return !matchesInternal(distribution);
        } else {
            return matchesInternal(distribution);
        }
    }

    protected abstract boolean matchesInternal(Distribution distribution);

    public boolean isCopy(GroupItem groupItem) {
        if (this == groupItem) return false;
        if (!(groupItem instanceof DistributionFilterGroupItem)) return false;

        DistributionFilterGroupItem that = (DistributionFilterGroupItem) groupItem;
        return inverted == that.inverted;
    }
}
